package klk.shop.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import klk.shop.objects.SpecialArticles;

/**
 * Diese Servlet befindet sich in der rechten Leiste des Shops.
 * Es zeigt eine bestimmte Anzahl von Aktionsartikeln nach dem
 * Zufallsprinzip an.
 * 
 * @author lueder
 * @version 1.0
 * @since 1.4
 */
public class PromotionsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	SpecialArticles articles;
	String path;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public PromotionsServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		Properties languageLocale = (Properties)session.getAttribute("languageProperty");
		String languageString = languageLocale.getProperty("locale", "en");
		
		articles = new SpecialArticles(8, 0, 4, "ASC", languageString);
		
		path = request.getContextPath() + "/";

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();

		out.println("<div class='right_box'>");
		out.println("<div class='title'><span class='title_icon'><img src='"
				+ path
				+ "images/bullet4.gif' alt='' title='' /></span>"+languageLocale.getProperty("promotions", "Promotions")+"</div> ");

		out.println(articles.toHtml(path));
		out.println(" </div>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
